home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / os2 / splot170.zip / demo / LINEDRAW.SPT < prev    next >
Text File  |  1996-05-27  |  7KB  |  319 lines

  1. /* This file illustrates how to generate a line drawing of apparatus */
  2. /* It makes heavy use of gsave() and grestore() and axes transformations*/
  3. /* to draw elements repeatedly in different locations and/or orientations */
  4. /* This is just one way to do this. */
  5.  
  6. #include <splot.h>
  7.  
  8. main()
  9.    {
  10.    /* it turned out too big in the end so scale it back some */
  11.    scale(0.75,0.75);
  12.  
  13.    /* draw Dewar */
  14.    tail();
  15.    gsave();
  16.    /* draw a slightly bigger tail around the first */
  17.    scale(1.25,1.05);
  18.    translate(-1.05,-0.5); 
  19.    tail();
  20.    grestore();
  21.  
  22.    /* draw lenses */
  23.    newpath();
  24.    set(LINECOLOUR,BROWN);
  25.    gsave();
  26.    translate(12.79,10.85);
  27.    rotate(90);
  28.    scale(2,2);
  29.    lens();
  30.    grestore();
  31.    gsave();
  32.    translate(11.09,6.21);
  33.    scale(0.5,0.5);
  34.    lens();
  35.    grestore();
  36.  
  37.    /* draw the prism */
  38.    gsave();
  39.    translate(10.84,10.6);
  40.    prism();
  41.    grestore();
  42.  
  43.    /* draw helium level */
  44.    set(LINECOLOUR,BLUE);
  45.    moveto(2.44,8.08);
  46.    curveto(3.13,7.66,3.82,8.68,4.13,7.96);
  47.    curveto(4.89,8.38,5.32,7.72,5.89,8.20);
  48.    curveto(6.58,7.72,7.08,8.74,7.77,8.08);
  49.    stroke();
  50.  
  51.    /* draw 45 degree fold mirror */
  52.    set(LINECOLOUR,BLACK);
  53.    moveto(4.07,11.72);
  54.    lineto(5.64,10.15,5.44,9.95,3.64,11.72);
  55.    closepath();
  56.  
  57.    /* draw diamnond anvil cell */
  58.    moveto(3.38,11.72);
  59.    lineto(6.82,11.72,6.82,17.07,7.33,17.07,7.33,17.73,2.88,17.73,2.88,17.07,3.38,17.07);
  60.    closepath();
  61.    moveto(3.82,17.72);
  62.    lineto(3.82,18,6.33,18,6.33,17.72);
  63.    stroke();
  64.  
  65.    /* draw plate and screws */
  66.    moveto(2.88,18.0);
  67.    lineto(7.33,18.0,7.33,18.76,2.88,18.76);
  68.    closepath();
  69.    stroke();
  70.    gsave();
  71.    translate(3.38,18.76);
  72.    screw(1.5);
  73.    translate(3.45,0);
  74.    screw(1.5);
  75.    grestore();
  76.  
  77.    /* draw heater */
  78.    gsave();
  79.    translate(7.0,13.03);
  80.    heater();
  81.    translate(-3.8,0);
  82.    heater();
  83.    grestore();
  84.  
  85.    /* draw slits */
  86.    gsave();
  87.    translate(21.8,11.0);
  88.    slit();
  89.    grestore();
  90.    gsave();
  91.    scale(1,-1);
  92.    translate(21.8,-10.6);
  93.    slit();
  94.    grestore();
  95.  
  96.    /* draw periscope */
  97.    moveto(22.82,10.45);
  98.    lineto(23.57,11.18);
  99.    rlineto(0,2, 0.75,0, 0,1.5, -2,0, 0,-1.5, 0.75,0, 0,-2, 0.5,0);
  100.    stroke();
  101.  
  102.    /* draw arrows */
  103.    moveto(25.66,14.07);
  104.    arrowto(25.66,14.79);
  105.    moveto(25.66,14.07);
  106.    arrowto(25.66,13.35);
  107.    stroke();
  108.  
  109.    /* draw screw drivers and light pipe */
  110.    moveto(4.76,18.76);
  111.    lineto(4.76,30.0);
  112.    moveto(5.45,18.76);
  113.    lineto(5.45,30.0);
  114.    stroke();
  115.    gsave();
  116.    translate(3.38,18.9);
  117.    driver();
  118.    translate(3.45,0);
  119.    driver();
  120.    grestore();
  121.  
  122.    /* white out some of the lines at */
  123.    /* the top that turned out too long */
  124.    white_box(1.17,29.67,8.61,31.20);
  125.    newpath();
  126.  
  127.    /* draw copper gasket */
  128.    gsave();
  129.    set(LINECOLOUR,GREEN);
  130.    set(LINEWIDTH,0.10);
  131.    moveto(4.57,13.7);
  132.    lineto(5.57,13.7);
  133.    stroke();
  134.    grestore();
  135.  
  136.    /* draw dashed lines in diamond cell */
  137.    set(LINESTYLE,0.5,0.25);
  138.    moveto(3.82,17.72);
  139.    lineto(3.82,12.60,6.33,12.60,6.33,17.72);
  140.    moveto(3.82,14.8);
  141.    lineto(6.33,14.8);
  142.    moveto(4.76,14.8);
  143.    lineto(4.76,18.76);
  144.    moveto(5.45,14.8);
  145.    lineto(5.45,18.76);
  146.    moveto(4.76,12.6);
  147.    lineto(4.38,11.72);
  148.    moveto(5.45,12.6);
  149.    lineto(5.83,11.72);
  150.    stroke();
  151.  
  152.    /* draw the sapphire anvils */
  153.    gsave();
  154.    translate(4.32,12.6);
  155.    anvil();
  156.    translate(1.5,2.2);
  157.    rotate(180);
  158.    anvil();
  159.    grestore();
  160.    stroke();
  161.  
  162.    /* draw light paths */
  163.    set(LINECOLOUR,MAGENTA);
  164.    moveto(5.1,13.57);
  165.    lineto(5.1,10.85,11.09,10.85,11.09,0.06);
  166.    moveto(13.35,12.9);
  167.    lineto(4.7,11.22,5.1,13.51,5.45,10.43,13.35,8.74);
  168.    moveto(13.35,12.9);
  169.    lineto(21.73,10.85,13.35,8.74);
  170.    stroke();
  171.  
  172.    /* add comments */
  173.    set(LINECOLOUR,BLACK);
  174.    set(LINESTYLE,0);
  175.    set(FONTWIDTH,1.0);
  176.    text(2.33,32.29,"High Pressure, Low Temperature Spectroscopy");
  177.    set(FONTWIDTH,0.6);
  178.    text(3.57,4.58,"Liquid He");
  179.    text(22.65,15.60,"CCD");
  180.    text(19.81,7.39,"Spectrometer");
  181.               text("   Slits");
  182.    text(9.5,16.7,"Sapphire Anvil Cell");
  183.    text(9.5,14,"Heater");
  184.    text(9.5,23.88,"Light Pipe");
  185.    text(9.5,27,"Screw Drivers");
  186.  
  187.    /* draw lines to labelled parts */
  188.    set(LINEWIDTH,0.01);
  189.    moveto(4.76,5.46);
  190.    lineto(5.68,6.91);
  191.    moveto(9.19,13.99);
  192.    lineto(7.27,13.75);
  193.    moveto(9.27,16.64);
  194.    lineto(7.02,16.16);
  195.    moveto(9.27,23.96);
  196.    lineto(5.68,23.64);
  197.    moveto(9.27,27.02);
  198.    lineto(7.27,26.38);
  199.    moveto(9.27,27.02);
  200.    lineto(3.76,26.78);
  201.    stroke();
  202.    }
  203.  
  204. int anvil()
  205.    {
  206.    /* draw a sapphire anvil */
  207.    newpath();
  208.    moveto(0,0);
  209.    rlineto(0,0.5,0.5,0.5,0.5,0,0.5,-0.5,0,-0.5);
  210.    stroke();
  211.    }
  212.  
  213. int screw(double len)
  214.    {
  215.    int i,j;
  216.    /* draw a screw using a loop for */
  217.    /* the threads */
  218.    newpath();
  219.    moveto(0,0);
  220.    rlineto(0.25,0,0,0.25,-0.5,0,0,-0.25);
  221.    closepath();
  222.    moveto(0.15,0);
  223.    rlineto(0,-len,-0.3,0,0,len);
  224.    moveto(-0.15,0);
  225.    j = (int) (len / 0.2);
  226.    for (i=0;i < j;i++)
  227.       {
  228.       rmoveto(0.3,0);
  229.       rlineto(-0.30,-0.20);
  230.       }
  231.    stroke();
  232.    }
  233.  
  234. int heater()
  235.    {
  236.    int i;
  237.    /* draw a heater using a loop */
  238.    /* for the windings */
  239.    double y = 0;
  240.    newpath();
  241.    moveto(0,0);
  242.    for (i=0;i < 5;i++)
  243.       {
  244.       moveto(0.1,y);
  245.       arcn(0,y,0.1,360,0);
  246.       y = y + 0.4;
  247.       }
  248.    stroke();
  249.    }
  250.  
  251. int slit()
  252.    {
  253.    /* draw a spectrometer slit */
  254.    newpath();
  255.    moveto(0,0);
  256.    rlineto(0,1.5,0.25,0,0,-1.25);
  257.    closepath();
  258.    stroke();
  259.    }
  260.  
  261. int driver()
  262.    {
  263.    /* draw long screw drivers */
  264.    newpath();
  265.    moveto(0,0);
  266.    rlineto(0.15,0,0,0.25,0.1,0,0,10.8);
  267.    moveto(0,0);
  268.    rlineto(-0.15,0,0,0.25,-0.1,0,0,10.8);
  269.    stroke();
  270.    }
  271.  
  272. int white_box(double x1,double y1,double x2,double y2)
  273.    { 
  274.    /* draw a white filled box for */
  275.    /* white out purposes. The parametrs */
  276.    /* passed in are the box corners */
  277.    newpath();
  278.    box(x1,y1,x2,y2);
  279.    gsave();
  280.    set(LINECOLOUR,WHITE);
  281.    fill();
  282.    grestore();
  283.    }
  284.  
  285. int lens()
  286.    {
  287.    /* draw a spherical lens using arcs */
  288.    newpath();
  289.    arcn(0,-4,4,110,70);
  290.    arcn(0,3.45,4,290,250);
  291.    closepath();
  292.    stroke();
  293.    }
  294.  
  295. int prism()
  296.    {
  297.    /* draw a prism */
  298.    newpath();
  299.    moveto(0,0.5);
  300.    rlineto(0,-0.5,0.5,0);
  301.    closepath();
  302.    stroke();
  303.    }
  304.  
  305. int tail()
  306.    {
  307.    /* draw the dewar tail */
  308.    set(LINECOLOUR,BLACK);
  309.    moveto(2.44,30);
  310.    lineto(2.44,6.33,7.77,6.33,7.77,30);
  311.    stroke();
  312.    /* draw windows */
  313.    set(LINECOLOUR,BROWN);
  314.    white_box(2.29,12.30,2.59,9.41);
  315.    stroke();
  316.    white_box(7.62,12.30,7.92,9.41);
  317.    stroke();
  318.    }
  319.